@extends('admin.common.app')
@section('css')
    <link rel="stylesheet" href="/admin/css/pagination.css">
@endsection
@section('cont')

    <section class="Hui-article-box">
        <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
            <span class="c-gray en">&gt;</span>
            管理员管理
            <span class="c-gray en">&gt;</span>
            节点列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
                <i class="Hui-iconfont">&#xe68f;</i>
            </a>
        </nav>
        <div class="Hui-article">
            <article class="cl pd-20">
                <form class="text-c" method="get"> 节点名称：
                    <input type="text" class="input-text" style="width:250px" placeholder="输入节点名称" value="{{request()->get('name')}}" name="name">
                    <button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜节点</button>
                </form>
                <div class="cl pd-5 bg-1 bk-gray mt-20">
                    <span class="l">

                        <a href="{{route('admin.node.create')}}"  class="btn btn-primary radius">
                            <i class="Hui-iconfont">&#xe600;</i>
                            添加节点</a>
                    </span>
                </div>
                @include('admin.common.msg')
                <table class="table table-border table-bordered table-bg">
                    <thead>
                    <tr class="text-c">
                        <th >ID</th>
                        <th>分类名称</th>
                        <th>节点名称</th>
                        <th>是否菜单</th>
                        <th>添加时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($data as $item)
                        <tr class="text-c">
                            <td>{{$item['id']}}</td>
                            <td class="text-l">
                                {{$item['html']}}{{$item['name']}}
                            </td>
                            <td>{{$item['route_name']}}</td>
                            <td>
                                @if($item['is_menu']==1)
                                    <span class="label label-success radius">菜单</span>
                                    @else
                                    <span class="label label-danger radius">否</span>
                                    @endif
                            </td>
                            <td>{{$item['created_at']}}</td>
                            <td class="td-manage">
                                <a href="{{route('admin.node.edit',$item['id'])}}" class="label label-success radius">修改</a>
                                <a href="{{route('admin.node.destroy',$item['id'])}}" class="label label-danger delbat radius">删除</a>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </article>
        </div>
    </section>
@endsection
@section('js')
    <script>
        //删除
        $('.delbat').click(function () {
            let url=$(this).attr('href');
            let _token="{{csrf_token()}}";
            const e=$(this).parents('tr');//父级 tr
            layer.confirm('真的删除行么', function(index){
                layer.close(index);

                $.ajax({
                    url,
                    type:'DELETE',
                    data:{_token},
                }).then(({status,msg})=>{
                    if (status == 0){
                        layer.msg(msg, {
                                icon: 2,
                                time:2000,
                                skin: 'layui-layer-molv' //样式类名
                            }, e.remove()//删除父级
                        )
                    }
                });
                //向服务端发送删除指令
            });
            //取消默认事件
            return false;
        });
    </script>
@endsection
